CPP=gcc
AS=as
AR=gar
LD=ld
TOBIN=objcopy
DD=dd
SRC = $(wildcard *.S)
PRE_OBJ = $(patsubst %.S, %.s, $(SRC))
OBJ = $(patsubst %.s, %.o, $(PRE_OBJ))
CFLAGS=-E -I../include -I../include/driver
ASFLAGS+=--32
ELFBIN=./../../bin/boot.elf
BIN=./../../bin/boot.bin

ifeq ($(DEBUG), ON)
ASFLAGS+= -g  --verbose
endif
all: $(ELFBIN)

echo:
	echo $(CPP)

$(ELFBIN): $(OBJ)
	$(LD) -Ttext=0x7e00 -melf_i386 -e bootloader -o $@ $^
	objcopy -O binary $(ELFBIN) $(BIN)
#	$(LD) --oformat binary -Ttext=0  -e bootloader -o $@ $^

$(OBJ): %.o: %.s
	$(AS) $(ASFLAGS) -o $@ $<

$(PRE_OBJ): %.s: %.S
	$(CPP) $(CFLAGS) $< -o $@

.PHONY: clean
clean:
	rm -f *.o *.s *.bin $(BIN) $(ELFBIN)
